﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master/Compras.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="Administrativo_Unidades_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../../Styles/GridView.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/GridView.js" type="text/javascript"></script>
    <link href="../../Styles/Administrativo.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/Botao.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager runat="server">
    </asp:ScriptManager>
    <asp:UpdateProgress ID="UPDepto" runat="server" 
        AssociatedUpdatePanelID="UPCadastro" DisplayAfter="200">
        <ProgressTemplate>
            <div id="Carregando">
                <div>
                    <img src="../../Images/Carregando.gif" />Carregando ...</div>
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:UpdatePanel ID="UPCadastro" runat="server">
        <ContentTemplate>
            <div id="CadastroDepartamento">
                <p>
                    <asp:Timer ID="TimerNovaUnidade" runat="server" Enabled="False" Interval="5000" 
                        OnTick="TimerNovaUnidade_Tick">
                    </asp:Timer>
                    <fieldset class="FieldCadastroDepartamento">
                        <legend>
                            <h1>
                                Nova Unidade</h1>
                        </legend>
                        <p>
                            Descrição:<br />
                            <asp:TextBox ID="TbUnidade" runat="server" CssClass="TextBox"></asp:TextBox><br />
                            <asp:Label ID="MsgUnidade" runat="server" CssClass="Aviso"></asp:Label>
                        </p>
                        <p>
                            <asp:Button ID="BtCadastrarDepto" runat="server" CssClass="Botao" Text="Cadastrar"
                                OnClick="BtCadastrarDepto_Click" /><br />
                            <asp:Label ID="MsgFim" runat="server" CssClass="Aviso"></asp:Label>
                        </p>
                    </fieldset>
                </p>
            </div>
            <p class="Titulo">
                Unidades</p>
            <asp:GridView ID="Itens" runat="server" CssClass="Grid" DataSourceID="SQLDeptos"
                GridLines="Horizontal" AutoGenerateColumns="False" DataKeyNames="Codigo" Width="450px"
                AllowPaging="True" AllowSorting="True">
                <Columns>
                    <asp:TemplateField HeaderText="Unidade" SortExpression="Unidade">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" CssClass="TextBox" 
                                Text='<%# Bind("Unidade") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Unidade") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Codigo" HeaderText="Codigo" SortExpression="Codigo" InsertVisible="False"
                        ReadOnly="True" Visible="False" />
                    <asp:TemplateField ShowHeader="False">
                        <EditItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                                CommandName="Update" Text="Confirmar"></asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                                CommandName="Cancel" Text="Cancelar"></asp:LinkButton>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                                CommandName="Edit" Text="Alterar"></asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                                CommandName="Delete" onclientclick="javascrit:return window.confirm(&quot;Você tem certeza que deseja deletar esta Unidade?&quot;)" Text="Apagar"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <AlternatingRowStyle CssClass="Linha2-Grid" />
                <EditRowStyle CssClass="LinhaAlterar" />
                <HeaderStyle CssClass="Cab-Grid" />
                <PagerSettings Mode="NumericFirstLast" />
                <RowStyle CssClass="Linha-Grid" />
            </asp:GridView>
            <asp:SqlDataSource ID="SQLDeptos" runat="server" ConnectionString="<%$ ConnectionStrings:Compras %>"
                ProviderName="<%$ ConnectionStrings:Compras.ProviderName %>" SelectCommand="SELECT Unidade, Codigo FROM unidade"
                DeleteCommand="DELETE FROM Unidade WHERE (Codigo = @Codigo)" 
                UpdateCommand="UPDATE unidade SET Unidade = @Unidade WHERE (unidade.Codigo = @Codigo)">
            </asp:SqlDataSource>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Itens" />
            <asp:AsyncPostBackTrigger ControlID="BtCadastrarDepto" />
            <asp:AsyncPostBackTrigger ControlID="TimerNovaUnidade" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>
